<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>多张图片垂直居中</title>
        <style type="text/css">
        .imgWrap li {
            float: left;
            border: solid 1px #666;
            margin: 10px 10px 0 0;
            list-style: none;
            background: #ffa url(images/gridBg.gif) repeat center;
        }
        .imgWrap a {
            width: 219px;
            height: 219px;
            display: block;
        }
        </style>
    </head>
    <body>
        <ul class="imgWrap clearfix">
            <li><a href="#" class="imgBox"><img src="../img/tourism2.png" alt="" /></a></li>
            <li><a href="#" class="imgBox"><img src="../img/tourism1.png" alt="" /></a></li>
            <li><a href="#" class="imgBox"><img src="../img/poster.png" alt="" /></a></li>
            <li><a href="#" class="imgBox"><img src="../img/puke/2.jpg" alt="" /></a></li>
        </ul>
        <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
            //先写一个小插件
            $.fn.imgVAlign=function(){
                return $(this).each(function(i){
                    //获取图片的src值，并定义给变量bg
                    var bg = $(this).attr("src");
                    //给图片的父元素定义背景图片的样式，并且背景图片
                    $(this).parent().css({"background": "url("+ bg +") no-repeat center center"
                    });
                    //将图片隐藏
                    $(this).css("opacity","0");
                });
            }
            //调用上面写的插件
            $(document).ready(function(){
                $(".imgBox img").imgVAlign();
            });
        </script>
    </body>
</html>